<!DOCTYPE html>
<html>
    <head>
        <title>Pick-up Game</title>
        <link rel="stylesheet" href="style.css" type="text/css" />
        <script src="http://code.jquery.com/jquery-latest.js"></script>
	<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
	<script>
	    $(document).ready(function(){
		$("#submitForm").validate();
	    });
	</script>
    </head>

    <body>    
        <?php
        include_once('menu.php');

        // connect to database
        $conn_str = 'host=dbsrv1.cdf.toronto.edu dbname=csc309g23 user=csc309g23 password=ipheid5h';
        $conn = pg_connect($conn_str);

        // query database
        $query = 'SELECT * FROM sports';
        $result = pg_query($conn, $query);
        ?>
            <div class="container">

        <?php if (!empty($_SESSION['username'])) : ?>
                <form id="submitForm" action="saveGame.php" method="post">
                    <h2>Create Game</h2>
                    <hr></hr>
                        <table>
                            <tr><td>Skill</td>
                                <td><select name="skill">
                                        <option>0-1</option>
                                        <option>1-2</option>
                                        <option>2-3</option>
                                        <option>3-4</option>
                                        <option>4-5</option>
                                    </select>
                                </td></tr>     
                            <tr><td>Sport</td>
                                <td><select name="sport">
                                        <?php while ($row = pg_fetch_row($result)) { ?>
                                            <option><?= $row[0] ?></option>
                                        <?php } ?>
                                    </select>
                                </td></tr>
                            </td></tr>
                            <tr><td>Address</td><td><input type="text" name="address" class="required" /></td></tr>
                            <tr><td>City</td><td><input type="text" name="city"  class="required" /></td></tr>
                            
                            <?php // create countries dropdown
			    $query = 'SELECT * FROM countries';
			    $result = pg_query($conn, $query);
			    ?>
			    <tr><td>Country</td>
                                <td><select name="country">
                                        <?php while ($row = pg_fetch_row($result)) { ?>
                                            <option><?= $row[0] ?></option>
                                        <?php } ?>
                                    </select>
                            </td></tr>
                            
                            <tr><td>Start</td><td><input type="text" name="start"  class="required"  id="start" /></td></tr>
                            <tr><td>End</td><td><input type="text" name="end"  class="required"  id="end" /></td></tr>
                            <tr><td></td><td><input type="submit" value="Create" /></td></tr>
                        </table>
                    </fieldset>
                </form>
        
        <?php
        else :
            header('Location: /');
        endif;
        ?>
            </div>
    </body>
</html>